package com.xinqi.service.impl;

import com.xinqi.service.HelloService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author xin麒
 * @date 2023/8/10 20:11
 */
@Slf4j
@Service
//@EnableAsync
public class HelloServiceImpl implements HelloService {

    @Autowired
    ThreadPoolTaskExecutor threadPoolTaskExecutor;

    @Override
    public Object springbootThreadPool(Long count) {
        try {
            threadPoolTaskExecutor.execute(() -> {
                try {
                    Thread.sleep(1000 * 1);
                    log.debug("v me 50");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "nice";
    }

//
//    @Autowired
//    private SimpleAsyncTaskExecutor simpleAsyncTaskExecutor;

    @Override
//    @Async
    public void simpleAsyncTaskExecutor(Long count) {
        try {
            Thread.sleep(1000 * 5);
            log.debug("v me 50");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }


}
